/**
 * 岗位详细信息编辑面板
 */	
Ext.namespace("Ext.ux.sysmeta");

Ext.ux.sysmeta.SysTableDetailPanel = Ext.extend(Ext.Panel, {

    title:'',
    layout:'fit',
    
    parentWinId: null,		//父窗口ID
    tableId: null,			//表ID
    owner:null,             //所属用户
    
    formPanel: null,
    
	// 组件事件初始化
	initComponent: function(){
		Ext.ux.sysmeta.SysTableDetailPanel.superclass.initComponent.call(this);
		
		// JSON解析
		var formReader = new Ext.data.JsonReader({
			root: 'result',
			id: 'id'
		},[
			{name:'id', mapping:'id'},
			{name:'tableName', mapping:'tableName'},	
			{name:'tableChineseComments', mapping:'tableChineseComments'},
			{name:'owner', mapping:'owner'},
			{name:'entityName', mapping:'entityName'},
			{name:'memo', mapping:'memo'}
		]);		
		
		//岗位信息显示面板	
		var tableInfForm = new Ext.FormPanel({
			region: 'center',
			labelWidth: 85,	
			reader: formReader,
			labelAlign: 'right',
			frame: true,
			items: [{
				xtype: 'fieldset',
	            title: '<span class="fs_tip">请输入表结构基本信息，标志 <span class="fs_flag">*</span> 字段为必填项</span>',
	            layout: 'form',
				items:[{
					xtype: 'textfield',
					fieldLabel: '<span class="fs_flag">*</span>&nbsp;表名',
					name: 'tableName',
					allowBlank: false,
					anchor: '98%'
				},{
					xtype: 'textfield',
					fieldLabel: '表注释',
					name: 'tableChineseComments',
					allowBlank: false,
					anchor: '98%'
				},{
					xtype: 'textfield',
					fieldLabel: '所属用户',           //只读
					name: 'owner',
					//allowBlank: false,
					anchor: '98%'
				},{
					xtype: 'textfield',
					fieldLabel: '<span class="fs_flag">*</span>&nbsp;实体名',//只读
					allowBlank: false,
					name: 'entityName',
					anchor: '98%'
				},{
					layout: 'form',     
					xtype: 'textarea',
					name: 'memo',
					width: 180,
					anchor: '98%',
					fieldLabel: '备注',
					hight:70
				},{                     //隐藏控件
					xtype: 'hidden',
					name: 'id'
				}]
			}],
			buttons:[{
				xtype: 'button',
				text: '&nbsp;&nbsp;保存',
				width: 90,
				iconCls: 'icon-middle-save',
				scale: 'medium',
				handler: this.saveTable,
				scope: this
			}]
	    });

	    //如果是弹出窗口则添加关闭窗口按钮
	    if(this.parentWinId != null){
	    	tableInfForm.addButton({
				text: '关闭窗口',
				width: 90,
				iconCls: 'icon-middle-cancel',
				scale: 'medium',
				handler: function(button, e){
					this.closeParentWin();
				},
				scope: this
			})
	    }

		if(this.owner != null){
			tableInfForm.form.findField('owner').setValue(this.owner);
		}
		
	    this.add(tableInfForm);
	    this.formPanel = tableInfForm;
	},
	
	//加载指定岗位信息
	loadTable: function(tableId){
		this.tableId = tableId;
		this.formPanel.load({
			url: 'sys-meta-table!input.action?id=' + tableId,
			waitMsg: '正在载入数据...',
			failure: function(){
				Ext.Msg.alert('系统提示', '无法加载指定岗位信息！');
			}
		});
	},
	
	
	//如果是弹出窗口则保存后要关闭
	closeParentWin: function(){
		var win = Ext.getCmp(this.parentWinId);
		if(win != null){
			win.close();
		}
	},
	
	//保存岗位信息
	saveTable: function(){
		if(this.formPanel.form.isValid()){
	    	this.formPanel.form.submit({
	    		url: 'sys-meta-table!save.action',
				success: function(from, action) {
					Ext.getCmp('treePanel').refresh();
					this.closeParentWin();
				},
				failure: function(form, action) {
					Ext.Msg.alert('系统提示', '更新岗位信息失败！');
				},
				waitMsg: '正在保存数据，请稍候...',
				scope: this
	    	});
	    }
	}
});
	
